var token = getToken();
let userx = JSON.parse(window.localStorage.getItem("userInfo"));
let user = null;
var res = playGet("/v1/api/users/cz/site/" + userx.id, "", "", token);
if (res.code == 200) {
  user = res.data;
} else {
  mui.alert(res.msg);
}

$("#sitetype").click(function () {
  let payList = [
    { value: "自提", text: "自提" },
    { value: "快递", text: "快递" },
  ];
  var picker = new mui.PopPicker();
  picker.setData(payList);
  picker.show(function (selectItems) {
    $("#sitetype").val(selectItems[0].value);
  });
});
if (user != null && user.length > 0) {
  $("#sitepeople").val(user[0].sitePeople);
  $("#site").val(user[0].site);
  $("#sitemobile").val(user[0].siteMobile);
  $("#sitetype").val(user[0].siteType);
}

$("#subPay").click(function () {
  let users = {
    sitePeople: $("#sitepeople").val(),
    site: $("#site").val(),
    siteMobile: $("#sitemobile").val(),
    userId: userx.id,
    siteType: $("#sitetype").val(),
  };
  if (checkJson(users) == false) {
    mui.alert("请填写完整");
    return false;
  }
  users["id"] = user.length != 0 ? user[0].id : null;
  var res = playPut("/v1/api/users/cs/site", "", users, token);
  if (res.code == 200) {
    mui.alert("修改成功");
    setTimeout(() => {
      location.href = "site.html";
    }, 1000);
  } else {
    mui.alert(res.msg);
  }
});
